<template>
  <view class="sort-field">
    <view v-for="item in tabList" :key="item.sort" class="field-item" :class="{active:item.sort==field}" @click.stop="_handleClick(item)">
      <text class="txt">{{item.name}}</text>
      <view class="u-flex u-flex-col">
        <u-icon name="arrow-up-fill" size="16" :color="type==1&&item.sort==field?'#E44435':'#969799'" />
        <u-icon name="arrow-down-fill" size="16" :color="type==2&&item.sort==field?'#E44435':'#969799'" />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'sortField',
  props: {
    tabList: {
      type: Array,
      required: true,
      default: () => []
    }
  },
  data() {
    return {
      field: 1, // sortField
      type: 2 // sortType-->2为down，1为up
    }
  },
  methods: {
    _handleClick(item) {
      if (item.sort === this.field) {
        this.type = this.type === 1 ? 2 : 1
      } else {
        this.field = item.sort
        this.type = 2
      }
      this.$emit('change', {
        sortField: this.field,
        sortType: this.type
      })
      // console.log(item)
    }
  }
}
</script>

<style lang="scss" scoped>
.sort-field {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  height: 100rpx;
  //padding: 0 56rpx;
  background-color: #FFFFFF;
  box-shadow: inset 0 -2rpx 0 #EEEEEE;
  .field-item {
    display: flex;
    align-items: center;
    //width: 33.3333%;
    height: 100%;
  }
  .txt {
    margin-right: 8rpx;
    font-size: 28rpx;
    line-height: 40rpx;
    color: rgba(0, 0, 0, 0.9);
  }
  .active .txt {
    color: $themeColor;
  }
}
</style>